Use case: HASH process using SHA1 algorithm in polling mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* This example is used with HASH processing */
uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x5f, 0x45, 0x56, 0x41, 0x4c};
uint8_t Sha1output[20]={0};
/* HASH Initialization and configuration */
hhash.Init.DataType = HASH_DATATYPE_8B;
HAL_HASH_Init(&hhash);
/* Process with oneshot HASH computing SHA1 algorithm */
HAL_HASH_SHA1_Start(&hhash, Msg65_Input, 65, Sha1output, 1);
/* Process with multi-buffer updating to compute SHA1 algorithm */
HAL_HASH_SHA1_Accmlt(&hhash, Msg65_Input, 29);
HAL_HASH_SHA1_Accmlt(&hhash, Msg65_Input+29, 33);
HAL_HASH_SHA1_Accmlt_End(&hhash, Msg65_Input+62, 3, Sha1output, 1);
/* De-initialization */
HAL_HASH_DeInit(&hhash);
|
/* This example is used with HASH processing */
uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x5f, 0x45, 0x56, 0x41, 0x4c};
uint8_t Sha1output[20]={0};
uint32_t sha1output_size;
/* HASH Initialization */
HAL_HASH_Init(&hhash, HAL_HASH);
/* Configure SHA1 algorithm */
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA1;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Process with oneshot HASH computing SHA1 algorithm */
/* When the input buffer size is not a multiple of the word size,
the last word of the message fed to the hash processor will be
configured by considering only the valid bits specified by NBLW */
HAL_HASH_Compute(&hhash, Msg65_Input, 65, Sha1output, 20, &sha1output_size, 1);
/* Process with multi-buffer updating to compute SHA1 algorithm */
/* When the input buffer size is not a multiple of the word size,
the remaining bytes of the last word of the current message will be
stored in the handle and processed with the next update operation */
HAL_HASH_Update(&hhash, Msg65_Input, 29, 1);
HAL_HASH_Update(&hhash, Msg65_Input+29, 33, 1);
HAL_HASH_Update(&hhash, Msg65_Input+62, 3, 1);
HAL_HASH_Finish(&hhash, Sha1output, 20, &sha1output_size, 1);
/* De-initialization */
HAL_HASH_DeInit(&hhash);
|
Key changes ¶
HAL2 uses unified HASH APIs (compute/update/finish) and selects the algorithm through a configuration function.
HAL2 supports multi-buffer HMAC in polling mode, while HAL1 supports only one-shot HMAC in polling mode.



